﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sahit.iSoilHotel.Domain.Seedwork.Specification;
using Sahit.iSoilHotel.Application.Seedwork;
using Sahit.iSoilHotel.Application.MainBoundedContext.Tavern.Interfaces;
using Sahit.iSoilHotel.Domain.MainBoundedContext.Tavern.Aggregates.RoomAgg;
using Sahit.iSoilHotel.Application.MainBoundedContext.DTO.RoomAgg;
using Sahit.iSoilHotel.Application.MainBoundedContext.DTO.FilterAgg;
using System.Linq.Expressions;

namespace Sahit.iSoilHotel.Application.MainBoundedContext.Tavern.Services
{
    public class RoomService:IRoomService
    {
        private readonly IRoomRepository roomRepository;
        private readonly IRoomTypeRepository roomTypeRepository;
        private readonly IBuildingRepository buildingRepository;

        public RoomService(IRoomRepository roomRepository, 
            IRoomTypeRepository roomTypeRepository,
            IBuildingRepository buildingRepository)
        {
            this.roomRepository = roomRepository;
            this.roomTypeRepository = roomTypeRepository;
            this.buildingRepository = buildingRepository;
        }

        public Room GetRoom(Guid roomID)
        {
            return roomRepository.Get(roomID);
        }

        public List<RoomTypeDTO> GetRoomType()
        {
            return roomTypeRepository.GetAll().ProjectedAsCollection<RoomTypeDTO>();
        }

        public List<RoomDTO> GetRoom(RoomFilterDTO filter)
        {
            //var filterRoom = RoomSpecifications.RoomSearch(filter.RoomStatusID,filter.RoomTypeID,filter.RoomNumber);
            //List<Room> rooms = roomRepository.AllMatching(filterRoom).ToList();
            var rooms = roomRepository.GetAll().ProjectedAsCollection<RoomDTO>();
            return rooms;
        }


        public List<BuildingDTO> GetAllBuildings()
        {
            var buildings = buildingRepository.GetAll();
            return buildings.ProjectedAsCollection<BuildingDTO>();
        }

        public void UpdateRoom(Room room)
        {

        }

        public void SetRoomStatus(Guid roomID, RoomStatus roomStatus)
        {
            var room = roomRepository.Get(roomID);
            room.Status = roomStatus;
            roomRepository.Modify(room);
        }
    }
}
